package StatusCache

import (
	LogUtils "IMServices/LogService"
	"IMServices/NetIO/Define"
	"IMServices/SqlUtils/MysqlUtils"
)

var mysqlClient = MysqlUtils.MysqlClient{}
var LoginInfoMap map[string]Define.LoginDefine

func Init() {
	LoginInfoMap = make(map[string]Define.LoginDefine)
	err := mysqlClient.StartMysqlService("127.0.0.1", "3306", "root", "123456", "imservices")
	if err != nil {
		LogUtils.LogError(err.Error())
	}
	selectUserInfo()
}

func selectUserInfo() {
	rows := mysqlClient.SelectModel("SELECT USER_NAME, USER_DOMAINID, USER_PWD, USER_LOGINMAC, USER_LOGINADDR FROM hs_user")
	for rows.Next() {
		var loginDefine Define.LoginDefine
		err := rows.Scan(&loginDefine.Name, &loginDefine.ServerId, &loginDefine.Password, &loginDefine.Macs, &loginDefine.Ip)
		if err != nil {
			LogUtils.LogError("查询出现异常", err)
		}
		LoginInfoMap[loginDefine.Name] = loginDefine
	}
}
